
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>11.1 生成源代码和二进制包 · 《CMake Cookbook》中文版</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="陈晓伟 chenxiaowei">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-pageview-count/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="11.2-chinese.html" />
    
    
    <link rel="prev" href="11.0-chinese.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../preface/preface-chinese.html">
            
                <a href="../preface/preface-chinese.html">
            
                    
                    前言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../chapter0/0.0-chinese.html">
            
                <a href="../chapter0/0.0-chinese.html">
            
                    
                    第0章 配置环境
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../chapter0/0.1-chinese.html">
            
                <a href="../chapter0/0.1-chinese.html">
            
                    
                    0.1 获取代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../chapter0/0.2-chinese.html">
            
                <a href="../chapter0/0.2-chinese.html">
            
                    
                    0.2 Docker镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../chapter0/0.3-chinese.html">
            
                <a href="../chapter0/0.3-chinese.html">
            
                    
                    0.3 安装必要的软件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../chapter0/0.4-chinese.html">
            
                <a href="../chapter0/0.4-chinese.html">
            
                    
                    0.4 测试环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../chapter0/0.5-chinese.html">
            
                <a href="../chapter0/0.5-chinese.html">
            
                    
                    0.5 上报问题并提出改进建议
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../chapter1/1.0-chinese.html">
            
                <a href="../chapter1/1.0-chinese.html">
            
                    
                    第1章 从可执行文件到库
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../chapter1/1.1-chinese.html">
            
                <a href="../chapter1/1.1-chinese.html">
            
                    
                    1.1 将单个源文件编译为可执行文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../chapter1/1.2-chinese.html">
            
                <a href="../chapter1/1.2-chinese.html">
            
                    
                    1.2 切换生成器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../chapter1/1.3-chinese.html">
            
                <a href="../chapter1/1.3-chinese.html">
            
                    
                    1.3 构建和链接静态库和动态库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../chapter1/1.4-chinese.html">
            
                <a href="../chapter1/1.4-chinese.html">
            
                    
                    1.4 用条件句控制编译
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../chapter1/1.5-chinese.html">
            
                <a href="../chapter1/1.5-chinese.html">
            
                    
                    1.5 向用户显示选项
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../chapter1/1.6-chinese.html">
            
                <a href="../chapter1/1.6-chinese.html">
            
                    
                    1.6 指定编译器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../chapter1/1.7-chinese.html">
            
                <a href="../chapter1/1.7-chinese.html">
            
                    
                    1.7 切换构建类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="../chapter1/1.8-chinese.html">
            
                <a href="../chapter1/1.8-chinese.html">
            
                    
                    1.8 设置编译器选项
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" data-path="../chapter1/1.9-chinese.html">
            
                <a href="../chapter1/1.9-chinese.html">
            
                    
                    1.9 为语言设定标准
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.10" data-path="../chapter1/1.10-chinese.html">
            
                <a href="../chapter1/1.10-chinese.html">
            
                    
                    1.10 使用控制流
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../chapter2/2.0-chinese.html">
            
                <a href="../chapter2/2.0-chinese.html">
            
                    
                    第2章 检测环境
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../chapter2/2.1-chinese.html">
            
                <a href="../chapter2/2.1-chinese.html">
            
                    
                    2.1 检测操作系统
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../chapter2/2.2-chinese.html">
            
                <a href="../chapter2/2.2-chinese.html">
            
                    
                    2.2 处理与平台相关的源代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../chapter2/2.3-chinese.html">
            
                <a href="../chapter2/2.3-chinese.html">
            
                    
                    2.3 处理与编译器相关的源代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../chapter2/2.4-chinese.html">
            
                <a href="../chapter2/2.4-chinese.html">
            
                    
                    2.4 检测处理器体系结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../chapter2/2.5-chinese.html">
            
                <a href="../chapter2/2.5-chinese.html">
            
                    
                    2.5 检测处理器指令集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="../chapter2/2.6-chinese.html">
            
                <a href="../chapter2/2.6-chinese.html">
            
                    
                    2.6 为Eigen库使能向量化
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../chapter3/3.0-chinese.html">
            
                <a href="../chapter3/3.0-chinese.html">
            
                    
                    第3章 检测外部库和程序
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../chapter3/3.1-chinese.html">
            
                <a href="../chapter3/3.1-chinese.html">
            
                    
                    3.1 检测Python解释器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../chapter3/3.2-chinese.html">
            
                <a href="../chapter3/3.2-chinese.html">
            
                    
                    3.2 检测Python库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../chapter3/3.3-chinese.html">
            
                <a href="../chapter3/3.3-chinese.html">
            
                    
                    3.3 检测Python模块和包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../chapter3/3.4-chinese.html">
            
                <a href="../chapter3/3.4-chinese.html">
            
                    
                    3.4 检测BLAS和LAPACK数学库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../chapter3/3.5-chinese.html">
            
                <a href="../chapter3/3.5-chinese.html">
            
                    
                    3.5 检测OpenMP的并行环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../chapter3/3.6-chinese.html">
            
                <a href="../chapter3/3.6-chinese.html">
            
                    
                    3.6 检测MPI的并行环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../chapter3/3.7-chinese.html">
            
                <a href="../chapter3/3.7-chinese.html">
            
                    
                    3.7 检测Eigen库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../chapter3/3.8-chinese.html">
            
                <a href="../chapter3/3.8-chinese.html">
            
                    
                    3.8 检测Boost库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="../chapter3/3.9-chinese.html">
            
                <a href="../chapter3/3.9-chinese.html">
            
                    
                    3.9 检测外部库:Ⅰ. 使用pkg-config
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.10" data-path="../chapter3/3.10-chinese.html">
            
                <a href="../chapter3/3.10-chinese.html">
            
                    
                    3.10 检测外部库:Ⅱ. 自定义find模块
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../chapter4/4.0-chinese.html">
            
                <a href="../chapter4/4.0-chinese.html">
            
                    
                    第4章 创建和运行测试
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../chapter4/4.1-chinese.html">
            
                <a href="../chapter4/4.1-chinese.html">
            
                    
                    4.1 创建一个简单的单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../chapter4/4.2-chinese.html">
            
                <a href="../chapter4/4.2-chinese.html">
            
                    
                    4.2 使用Catch2库进行单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../chapter4/4.3-chinese.html">
            
                <a href="../chapter4/4.3-chinese.html">
            
                    
                    4.3 使用Google Test库进行单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../chapter4/4.4-chinese.html">
            
                <a href="../chapter4/4.4-chinese.html">
            
                    
                    4.4 使用Boost Test进行单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../chapter4/4.5-chinese.html">
            
                <a href="../chapter4/4.5-chinese.html">
            
                    
                    4.5 使用动态分析来检测内存缺陷
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6" data-path="../chapter4/4.6-chinese.html">
            
                <a href="../chapter4/4.6-chinese.html">
            
                    
                    4.6 预期测试失败
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.7" data-path="../chapter4/4.7-chinese.html">
            
                <a href="../chapter4/4.7-chinese.html">
            
                    
                    4.7 使用超时测试运行时间过长的测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.8" data-path="../chapter4/4.8-chinese.html">
            
                <a href="../chapter4/4.8-chinese.html">
            
                    
                    4.8 并行测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.9" data-path="../chapter4/4.9-chinese.html">
            
                <a href="../chapter4/4.9-chinese.html">
            
                    
                    4.9 运行测试子集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.10" data-path="../chapter4/4.10-chinese.html">
            
                <a href="../chapter4/4.10-chinese.html">
            
                    
                    4.10 使用测试固件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../chapter5/5.0-chinese.html">
            
                <a href="../chapter5/5.0-chinese.html">
            
                    
                    第5章 配置时和构建时的操作
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../chapter5/5.1-chinese.html">
            
                <a href="../chapter5/5.1-chinese.html">
            
                    
                    5.1 使用平台无关的文件操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../chapter5/5.2-chinese.html">
            
                <a href="../chapter5/5.2-chinese.html">
            
                    
                    5.2 配置时运行自定义命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../chapter5/5.3-chinese.html">
            
                <a href="../chapter5/5.3-chinese.html">
            
                    
                    5.3 构建时运行自定义命令:Ⅰ. 使用add_custom_command
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../chapter5/5.4-chinese.html">
            
                <a href="../chapter5/5.4-chinese.html">
            
                    
                    5.4 构建时运行自定义命令:Ⅱ. 使用add_custom_target
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="../chapter5/5.5-chinese.html">
            
                <a href="../chapter5/5.5-chinese.html">
            
                    
                    5.5 构建时为特定目标运行自定义命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" data-path="../chapter5/5.6-chinese.html">
            
                <a href="../chapter5/5.6-chinese.html">
            
                    
                    5.6 探究编译和链接命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.7" data-path="../chapter5/5.7-chinese.html">
            
                <a href="../chapter5/5.7-chinese.html">
            
                    
                    5.7 探究编译器标志命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.8" data-path="../chapter5/5.8-chinese.html">
            
                <a href="../chapter5/5.8-chinese.html">
            
                    
                    5.8 探究可执行命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.9" data-path="../chapter5/5.9-chinese.html">
            
                <a href="../chapter5/5.9-chinese.html">
            
                    
                    5.9 使用生成器表达式微调配置和编译
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../chapter6/6.0-chinese.html">
            
                <a href="../chapter6/6.0-chinese.html">
            
                    
                    第6章 生成源码
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../chapter6/6.1-chinese.html">
            
                <a href="../chapter6/6.1-chinese.html">
            
                    
                    6.1 配置时生成源码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../chapter6/6.2-chinese.html">
            
                <a href="../chapter6/6.2-chinese.html">
            
                    
                    6.2 使用Python在配置时生成源码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="../chapter6/6.3-chinese.html">
            
                <a href="../chapter6/6.3-chinese.html">
            
                    
                    6.3 构建时使用Python生成源码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4" data-path="../chapter6/6.4-chinese.html">
            
                <a href="../chapter6/6.4-chinese.html">
            
                    
                    6.4 记录项目版本信息以便报告
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.5" data-path="../chapter6/6.5-chinese.html">
            
                <a href="../chapter6/6.5-chinese.html">
            
                    
                    6.5 从文件中记录项目版本
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.6" data-path="../chapter6/6.6-chinese.html">
            
                <a href="../chapter6/6.6-chinese.html">
            
                    
                    6.6 配置时记录Git Hash值
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.7" data-path="../chapter6/6.7-chinese.html">
            
                <a href="../chapter6/6.7-chinese.html">
            
                    
                    6.7 构建时记录Git Hash值
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../chapter7/7.0-chinese.html">
            
                <a href="../chapter7/7.0-chinese.html">
            
                    
                    第7章 构建项目
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../chapter7/7.1-chinese.html">
            
                <a href="../chapter7/7.1-chinese.html">
            
                    
                    7.1 使用函数和宏重用代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../chapter7/7.2-chinese.html">
            
                <a href="../chapter7/7.2-chinese.html">
            
                    
                    7.2 将CMake源代码分成模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../chapter7/7.3-chinese.html">
            
                <a href="../chapter7/7.3-chinese.html">
            
                    
                    7.3 编写函数来测试和设置编译器标志
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="../chapter7/7.4-chinese.html">
            
                <a href="../chapter7/7.4-chinese.html">
            
                    
                    7.4 用指定参数定义函数或宏
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" data-path="../chapter7/7.5-chinese.html">
            
                <a href="../chapter7/7.5-chinese.html">
            
                    
                    7.5 重新定义函数和宏
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.6" data-path="../chapter7/7.6-chinese.html">
            
                <a href="../chapter7/7.6-chinese.html">
            
                    
                    7.6 使用废弃函数、宏和变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.7" data-path="../chapter7/7.7-chinese.html">
            
                <a href="../chapter7/7.7-chinese.html">
            
                    
                    7.7 add_subdirectory的限定范围
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.8" data-path="../chapter7/7.8-chinese.html">
            
                <a href="../chapter7/7.8-chinese.html">
            
                    
                    7.8 使用target_sources避免全局变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.9" data-path="../chapter7/7.9-chinese.html">
            
                <a href="../chapter7/7.9-chinese.html">
            
                    
                    7.9 组织Fortran项目
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../chapter8/8.0-chinese.html">
            
                <a href="../chapter8/8.0-chinese.html">
            
                    
                    第8章 超级构建模式
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../chapter8/8.1-chinese.html">
            
                <a href="../chapter8/8.1-chinese.html">
            
                    
                    8.1 使用超级构建模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../chapter8/8.2-chinese.html">
            
                <a href="../chapter8/8.2-chinese.html">
            
                    
                    8.2 使用超级构建管理依赖项:Ⅰ.Boost库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.3" data-path="../chapter8/8.3-chinese.html">
            
                <a href="../chapter8/8.3-chinese.html">
            
                    
                    8.3 使用超级构建管理依赖项:Ⅱ.FFTW库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.4" data-path="../chapter8/8.4-chinese.html">
            
                <a href="../chapter8/8.4-chinese.html">
            
                    
                    8.4 使用超级构建管理依赖项:Ⅲ.Google Test框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.5" data-path="../chapter8/8.5-chinese.html">
            
                <a href="../chapter8/8.5-chinese.html">
            
                    
                    8.5 使用超级构建支持项目
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../chapter9/9.0-chinese.html">
            
                <a href="../chapter9/9.0-chinese.html">
            
                    
                    第9章 语言混合项目
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../chapter9/9.1-chinese.html">
            
                <a href="../chapter9/9.1-chinese.html">
            
                    
                    9.1 使用C/C++库构建Fortran项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.2" data-path="../chapter9/9.2-chinese.html">
            
                <a href="../chapter9/9.2-chinese.html">
            
                    
                    9.2 使用Fortran库构建C/C++项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.3" data-path="../chapter9/9.3-chinese.html">
            
                <a href="../chapter9/9.3-chinese.html">
            
                    
                    9.3 使用Cython构建C++和Python项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.4" data-path="../chapter9/9.4-chinese.html">
            
                <a href="../chapter9/9.4-chinese.html">
            
                    
                    9.4 使用Boost.Python构建C++和Python项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.5" data-path="../chapter9/9.5-chinese.html">
            
                <a href="../chapter9/9.5-chinese.html">
            
                    
                    9.5 使用pybind11构建C++和Python项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.6" data-path="../chapter9/9.6-chinese.html">
            
                <a href="../chapter9/9.6-chinese.html">
            
                    
                    9.6 使用Python CFFI混合C，C++，Fortran和Python
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../chapter10/10.0-chinese.html">
            
                <a href="../chapter10/10.0-chinese.html">
            
                    
                    第10章 编写安装程序
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../chapter10/10.1-chinese.html">
            
                <a href="../chapter10/10.1-chinese.html">
            
                    
                    10.1 安装项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.2" data-path="../chapter10/10.2-chinese.html">
            
                <a href="../chapter10/10.2-chinese.html">
            
                    
                    10.2 生成输出头文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.3" data-path="../chapter10/10.3-chinese.html">
            
                <a href="../chapter10/10.3-chinese.html">
            
                    
                    10.3 输出目标
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.4" data-path="../chapter10/10.4-chinese.html">
            
                <a href="../chapter10/10.4-chinese.html">
            
                    
                    10.4 安装超级构建
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="11.0-chinese.html">
            
                <a href="11.0-chinese.html">
            
                    
                    第11章 打包项目
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.14.1" data-path="11.1-chinese.html">
            
                <a href="11.1-chinese.html">
            
                    
                    11.1 生成源代码和二进制包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.2" data-path="11.2-chinese.html">
            
                <a href="11.2-chinese.html">
            
                    
                    11.2 通过PyPI发布使用CMake/pybind11构建的C++/Python项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.3" data-path="11.3-chinese.html">
            
                <a href="11.3-chinese.html">
            
                    
                    11.3 通过PyPI发布使用CMake/CFFI构建C/Fortran/Python项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.4" data-path="11.4-chinese.html">
            
                <a href="11.4-chinese.html">
            
                    
                    11.4 以Conda包的形式发布一个简单的项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.5" data-path="11.5-chinese.html">
            
                <a href="11.5-chinese.html">
            
                    
                    11.5 将Conda包作为依赖项发布给项目
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../chapter12/12.0-chinese.html">
            
                <a href="../chapter12/12.0-chinese.html">
            
                    
                    第12章 构建文档
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.1" data-path="../chapter12/12.1-chinese.html">
            
                <a href="../chapter12/12.1-chinese.html">
            
                    
                    12.1 使用Doxygen构建文档
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2" data-path="../chapter12/12.2-chinese.html">
            
                <a href="../chapter12/12.2-chinese.html">
            
                    
                    12.2 使用Sphinx构建文档
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3" data-path="../chapter12/12.3-chinese.html">
            
                <a href="../chapter12/12.3-chinese.html">
            
                    
                    12.3 结合Doxygen和Sphinx
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="../chapter13/13.0-chinese.html">
            
                <a href="../chapter13/13.0-chinese.html">
            
                    
                    第13章 选择生成器和交叉编译
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.16.1" data-path="../chapter13/13.1-chinese.html">
            
                <a href="../chapter13/13.1-chinese.html">
            
                    
                    13.1 使用CMake构建Visual Studio 2017项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16.2" data-path="../chapter13/13.2-chinese.html">
            
                <a href="../chapter13/13.2-chinese.html">
            
                    
                    13.2 交叉编译hello world示例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16.3" data-path="../chapter13/13.3-chinese.html">
            
                <a href="../chapter13/13.3-chinese.html">
            
                    
                    13.3 使用OpenMP并行化交叉编译Windows二进制文件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="../chapter14/14.0-chinese.html">
            
                <a href="../chapter14/14.0-chinese.html">
            
                    
                    第14章 测试面板
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.17.1" data-path="../chapter14/14.1-chinese.html">
            
                <a href="../chapter14/14.1-chinese.html">
            
                    
                    14.1 将测试部署到CDash
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.2" data-path="../chapter14/14.2-chinese.html">
            
                <a href="../chapter14/14.2-chinese.html">
            
                    
                    14.2 CDash显示测试覆盖率
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.3" data-path="../chapter14/14.3-chinese.html">
            
                <a href="../chapter14/14.3-chinese.html">
            
                    
                    14.3 使用AddressSanifier向CDash报告内存缺陷
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.4" data-path="../chapter14/14.4-chinese.html">
            
                <a href="../chapter14/14.4-chinese.html">
            
                    
                    14.4 使用ThreadSaniiser向CDash报告数据争用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="../chapter15/15.0-chinese.html">
            
                <a href="../chapter15/15.0-chinese.html">
            
                    
                    第15章 使用CMake构建已有项目
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.18.1" data-path="../chapter15/15.1-chinese.html">
            
                <a href="../chapter15/15.1-chinese.html">
            
                    
                    15.1 如何开始迁移项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.2" data-path="../chapter15/15.2-chinese.html">
            
                <a href="../chapter15/15.2-chinese.html">
            
                    
                    15.2 生成文件并编写平台检查
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.3" data-path="../chapter15/15.3-chinese.html">
            
                <a href="../chapter15/15.3-chinese.html">
            
                    
                    15.3 检测所需的链接和依赖关系
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.4" data-path="../chapter15/15.4-chinese.html">
            
                <a href="../chapter15/15.4-chinese.html">
            
                    
                    15.4 复制编译标志
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.5" data-path="../chapter15/15.5-chinese.html">
            
                <a href="../chapter15/15.5-chinese.html">
            
                    
                    15.5 移植测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.6" data-path="../chapter15/15.6-chinese.html">
            
                <a href="../chapter15/15.6-chinese.html">
            
                    
                    15.6 移植安装目标
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.7" data-path="../chapter15/15.7-chinese.html">
            
                <a href="../chapter15/15.7-chinese.html">
            
                    
                    15.7 进一步迁移的措施
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.8" data-path="../chapter15/15.8-chinese.html">
            
                <a href="../chapter15/15.8-chinese.html">
            
                    
                    15.8 项目转换为CMake的常见问题
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.19" data-path="../chapter16/16.0-chinese.html">
            
                <a href="../chapter16/16.0-chinese.html">
            
                    
                    第16章 可能感兴趣的书
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.19.1" data-path="../chapter16/16.1-chinese.html">
            
                <a href="../chapter16/16.1-chinese.html">
            
                    
                    16.1 留下评论——让其他读者知道你的想法
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="http://www.bczl.xyz/" target="blank" class="gitbook-link">
            编程之路
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >11.1 生成源代码和二进制包</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="111-&#x751F;&#x6210;&#x6E90;&#x4EE3;&#x7801;&#x548C;&#x4E8C;&#x8FDB;&#x5236;&#x5305;">11.1 &#x751F;&#x6210;&#x6E90;&#x4EE3;&#x7801;&#x548C;&#x4E8C;&#x8FDB;&#x5236;&#x5305;</h1>
<p><strong>NOTE</strong>:<em>&#x6B64;&#x793A;&#x4F8B;&#x4EE3;&#x7801;&#x53EF;&#x4EE5;&#x5728; <a href="https://github.com/dev-cafe/cmake-cookbook/tree/v1.0/chapter-11/recipe-01" target="_blank">https://github.com/dev-cafe/cmake-cookbook/tree/v1.0/chapter-11/recipe-01</a> &#x4E2D;&#x627E;&#x5230;&#x3002;&#x8BE5;&#x793A;&#x4F8B;&#x5728;CMake 3.6&#x7248;(&#x6216;&#x66F4;&#x9AD8;&#x7248;&#x672C;)&#x4E2D;&#x662F;&#x6709;&#x6548;&#x7684;&#xFF0C;&#x5E76;&#x4E14;&#x5DF2;&#x7ECF;&#x5728;GNU/Linux&#x3001;macOS&#x548C;Windows&#x4E0A;&#x8FDB;&#x884C;&#x8FC7;&#x6D4B;&#x8BD5;&#x3002;</em></p>
<p>&#x5982;&#x679C;&#x4EE3;&#x7801;&#x662F;&#x5F00;&#x6E90;&#x7684;&#xFF0C;&#x7528;&#x6237;&#x5C06;&#x80FD;&#x591F;&#x4E0B;&#x8F7D;&#x9879;&#x76EE;&#x7684;&#x6E90;&#x4EE3;&#x7801;&#xFF0C;&#x5E76;&#x4F7F;&#x7528;&#x5B8C;&#x5168;&#x5B9A;&#x5236;&#x7684;CMake&#x811A;&#x672C;&#x81EA;&#x884C;&#x6784;&#x5EFA;&#x3002;&#x5F53;&#x7136;&#xFF0C;&#x6253;&#x5305;&#x64CD;&#x4F5C;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x811A;&#x672C;&#x5B8C;&#x6210;&#xFF0C;&#x4F46;&#x662F;CPack&#x63D0;&#x4F9B;&#x4E86;&#x66F4;&#x7B80;&#x5355;&#x548C;&#x53EF;&#x79FB;&#x690D;&#x7684;&#x66FF;&#x4EE3;&#x65B9;&#x6848;&#x3002;&#x672C;&#x793A;&#x4F8B;&#x5C06;&#x6307;&#x5BFC;&#x60A8;&#x521B;&#x5EFA;&#x4E00;&#x4E9B;&#x5305;:</p>
<ul>
<li><strong>&#x6E90;&#x4EE3;&#x7801;&#x5305;</strong>&#xFF1A;&#x53EF;&#x4EE5;&#x5C06;&#x6E90;&#x4EE3;&#x7801;&#x76F4;&#x63A5;&#x538B;&#x7F29;&#x6210;&#x5F52;&#x6863;&#x6587;&#x4EF6;&#xFF0C;&#x8FDB;&#x884C;&#x53D1;&#x9001;&#x3002;&#x7528;&#x6237;&#x5C06;&#x4E0D;&#x5FC5;&#x4E3A;&#x7279;&#x5B9A;&#x7684;&#x7248;&#x672C;&#x63A7;&#x5236;&#x7CFB;&#x7EDF;&#x64CD;&#x5FC3;&#x3002;</li>
<li><strong>&#x4E8C;&#x8FDB;&#x5236;&#x5305;</strong>&#xFF1A;&#x5DE5;&#x5177;&#x5C06;&#x65B0;&#x6784;&#x5EFA;&#x7684;&#x76EE;&#x6807;&#x4EE5;&#x6253;&#x5305;&#x7684;&#x65B9;&#x5F0F;&#x5230;&#x5F52;&#x6863;&#x6587;&#x4EF6;&#x4E2D;&#x3002;&#x8FD9;&#x4E2A;&#x529F;&#x80FD;&#x975E;&#x5E38;&#x6709;&#x7528;&#xFF0C;&#x4F46;&#x53EF;&#x80FD;&#x4E0D;&#x591F;&#x5065;&#x58EE;&#xFF0C;&#x65E0;&#x6CD5;&#x53D1;&#x5E03;&#x5E93;&#x548C;&#x53EF;&#x6267;&#x884C;&#x7A0B;&#x5E8F;&#x3002;</li>
<li><strong>&#x5E73;&#x53F0;&#x539F;&#x751F;&#x7684;&#x4E8C;&#x8FDB;&#x5236;&#x5B89;&#x88C5;</strong>&#xFF1A;CPack&#x80FD;&#x591F;&#x4EE5;&#x8BB8;&#x591A;&#x4E0D;&#x540C;&#x7684;&#x683C;&#x5F0F;&#x751F;&#x6210;&#x4E8C;&#x8FDB;&#x5236;&#x5B89;&#x88C5;&#x7A0B;&#x5E8F;&#xFF0C;&#x56E0;&#x6B64;&#x53EF;&#x4EE5;&#x5C06;&#x8F6F;&#x4EF6;&#x53D1;&#x5E03;&#x5230;&#x4E0D;&#x540C;&#x7684;&#x5E73;&#x53F0;&#x3002;&#x6211;&#x4EEC;&#x5C06;&#x5C55;&#x793A;&#x5982;&#x4F55;&#x751F;&#x6210;&#x5B89;&#x88C5;&#x7A0B;&#x5E8F;:<ul>
<li>&#x57FA;&#x4E8E;Debian&#x7684;GNU/Linux&#x53D1;&#x884C;&#x7248;&#x7684;<code>.deb</code>&#x683C;&#x5F0F;&#xFF1A; <a href="https://manpages.debian.org/unstable/dpkg-dev/deb.5.en.html" target="_blank">https://manpages.debian.org/unstable/dpkg-dev/deb.5.en.html</a></li>
<li>&#x57FA;&#x4E8E;Red Hat&#x7684;GNU/Linux&#x53D1;&#x884C;&#x7248;&#x7684;<code>.rpm</code>&#x683C;&#x5F0F;&#xFF1A; <a href="http://rpm.org/" target="_blank">http://rpm.org/</a></li>
<li>macOS&#x5305;&#x7684;<code>.dmg</code>&#x683C;&#x5F0F;: <a href="https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html" target="_blank">https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html</a></li>
<li>Windows&#x7684;NSIS&#x683C;&#x5F0F;: <a href="http://nsis.sourceforge.net/Main_Page" target="_blank">http://nsis.sourceforge.net/Main_Page</a></li>
</ul>
</li>
</ul>
<h2 id="&#x51C6;&#x5907;&#x5DE5;&#x4F5C;">&#x51C6;&#x5907;&#x5DE5;&#x4F5C;</h2>
<p>&#x6211;&#x4EEC;&#x5C06;&#x4F7F;&#x7528;&#x7B2C;10&#x7AE0;&#x7B2C;3&#x8282;&#x7684;&#x793A;&#x4F8B;&#xFF0C;&#x9879;&#x76EE;&#x6811;&#x7531;&#x4EE5;&#x4E0B;&#x76EE;&#x5F55;&#x548C;&#x6587;&#x4EF6;&#x7EC4;&#x6210;:</p>
<pre><code class="lang-shell">.
&#x251C;&#x2500;&#x2500; cmake
&#x2502;    &#x251C;&#x2500;&#x2500; coffee.icns
&#x2502;    &#x251C;&#x2500;&#x2500; Info.plist.in
&#x2502;    &#x2514;&#x2500;&#x2500; messageConfig.cmake.in
&#x251C;&#x2500;&#x2500; CMakeCPack.cmake
&#x251C;&#x2500;&#x2500; CMakeLists.txt
&#x251C;&#x2500;&#x2500; INSTALL.md
&#x251C;&#x2500;&#x2500; LICENSE
&#x251C;&#x2500;&#x2500; src
&#x2502;    &#x251C;&#x2500;&#x2500; CMakeLists.txt
&#x2502;    &#x251C;&#x2500;&#x2500; hello-world.cpp
&#x2502;    &#x251C;&#x2500;&#x2500; Message.cpp
&#x2502;    &#x2514;&#x2500;&#x2500; Message.hpp
&#x2514;&#x2500;&#x2500; tests
    &#x251C;&#x2500;&#x2500; CMakeLists.txt
    &#x2514;&#x2500;&#x2500; use_target
        &#x251C;&#x2500;&#x2500; CMakeLists.txt
        &#x2514;&#x2500;&#x2500; use_message.cpp
</code></pre>
<p>&#x7531;&#x4E8E;&#x672C;&#x793A;&#x4F8B;&#x7684;&#x91CD;&#x70B9;&#x662F;&#x4F7F;&#x7528;CPack&#xFF0C;&#x6240;&#x4EE5;&#x4E0D;&#x4F1A;&#x8BA8;&#x8BBA;&#x6E90;&#x7801;&#x3002;&#x6211;&#x4EEC;&#x53EA;&#x4F1A;&#x5728;<code>CMakeCPack.cmake</code>&#x4E2D;&#x6DFB;&#x52A0;&#x6253;&#x5305;&#x6307;&#x4EE4;&#x3002;&#x6B64;&#x5916;&#xFF0C;&#x8FD8;&#x6DFB;&#x52A0;&#x4E86;<code>INSTALL.md</code>&#x548C;<code>LICENSE</code>&#x6587;&#x4EF6;&#xFF1A;&#x6253;&#x5305;&#x8981;&#x6C42;&#x9700;&#x8981;&#x5305;&#x542B;&#x5B89;&#x88C5;&#x8BF4;&#x660E;&#x548C;&#x9879;&#x76EE;&#x8BB8;&#x53EF;&#x4FE1;&#x606F;&#x3002;</p>
<h2 id="&#x5177;&#x4F53;&#x5B9E;&#x65BD;">&#x5177;&#x4F53;&#x5B9E;&#x65BD;</h2>
<p>&#x8BA9;&#x6211;&#x4EEC;&#x770B;&#x770B;&#x9700;&#x8981;&#x6DFB;&#x52A0;&#x5230;&#x8FD9;&#x4E2A;&#x9879;&#x76EE;&#x4E2D;&#x7684;&#x6253;&#x5305;&#x6307;&#x4EE4;&#x3002;&#x6211;&#x4EEC;&#x5C06;&#x5728;<code>CMakeCPack.cmake</code>&#x4E2D;&#x6536;&#x96C6;&#x5B83;&#x4EEC;&#xFF0C;&#x5E76;&#x5728;&#x5728;<code>CMakeLists.txt</code>&#x7684;&#x672B;&#x5C3E;&#x5305;&#x542B;&#x8FD9;&#x4E2A;&#x6A21;&#x5757;<code>include(cmakecpackage.cmake)</code>:</p>
<ol>
<li><p>&#x6211;&#x4EEC;&#x58F0;&#x660E;&#x5305;&#x7684;&#x540D;&#x79F0;&#xFF0C;&#x4E0E;&#x9879;&#x76EE;&#x7684;&#x540D;&#x79F0;&#x76F8;&#x540C;&#xFF0C;&#x56E0;&#x6B64;&#x6211;&#x4EEC;&#x4F7F;&#x7528;<code>PROJECT_NAME</code>&#x7684;CMake&#x53D8;&#x91CF;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">set</span>(CPACK_PACKAGE_NAME <span class="hljs-string">&quot;${PROJECT_NAME}&quot;</span>)
</code></pre>
</li>
<li><p>&#x58F0;&#x660E;&#x5305;&#x7684;&#x4F9B;&#x5E94;&#x5546;&#xFF1A;</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">set</span>(CPACK_PACKAGE_VENDOR <span class="hljs-string">&quot;CMake Cookbook&quot;</span>)
</code></pre>
</li>
<li><p>&#x6253;&#x5305;&#x7684;&#x6E90;&#x4EE3;&#x7801;&#x5C06;&#x5305;&#x62EC;&#x4E00;&#x4E2A;&#x63CF;&#x8FF0;&#x6587;&#x4EF6;&#x3002;&#x8FD9;&#x662F;&#x5E26;&#x6709;&#x5B89;&#x88C5;&#x8BF4;&#x660E;&#x7684;&#x7EAF;&#x6587;&#x672C;&#x6587;&#x4EF6;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">set</span>(CPACK_PACKAGE_DESCRIPTION_FILE <span class="hljs-string">&quot;${PROJECT_SOURCE_DIR}/INSTALL.md&quot;</span>)
</code></pre>
</li>
<li><p>&#x8FD8;&#x6DFB;&#x52A0;&#x4E86;&#x4E00;&#x4E2A;&#x5305;&#x7684;&#x63CF;&#x8FF0;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">set</span>(CPACK_PACKAGE_DESCRIPTION_SUMMARY <span class="hljs-string">&quot;message: a small messaging library&quot;</span>)
</code></pre>
</li>
<li><p>&#x8BB8;&#x53EF;&#x8BC1;&#x6587;&#x4EF6;&#x4E5F;&#x5C06;&#x5305;&#x62EC;&#x5728;&#x5305;&#x4E2D;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">set</span>(CPACK_RESOURCE_FILE_LICENSE <span class="hljs-string">&quot;${PROJECT_SOURCE_DIR}/LICENSE&quot;</span>)
</code></pre>
</li>
<li><p>&#x4ECE;&#x53D1;&#x5E03;&#x5305;&#x4E2D;&#x5B89;&#x88C5;&#x65F6;&#xFF0C;&#x6587;&#x4EF6;&#x5C06;&#x653E;&#x5728;<code>/opt/recipe-01</code>&#x76EE;&#x5F55;&#x4E0B;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">set</span>(CPACK_PACKAGING_INSTALL_PREFIX <span class="hljs-string">&quot;/opt/${PROJECT_NAME}&quot;</span>)
</code></pre>
</li>
<li><p>CPack&#x6240;&#x9700;&#x7684;&#x4E3B;&#x8981;&#x3001;&#x6B21;&#x8981;&#x548C;&#x8865;&#x4E01;&#x7248;&#x672C;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">set</span>(CPACK_PACKAGE_VERSION_MAJOR <span class="hljs-string">&quot;${PROJECT_VERSION_MAJOR}&quot;</span>)
<span class="hljs-keyword">set</span>(CPACK_PACKAGE_VERSION_MINOR <span class="hljs-string">&quot;${PROJECT_VERSION_MINOR}&quot;</span>)
<span class="hljs-keyword">set</span>(CPACK_PACKAGE_VERSION_PATCH <span class="hljs-string">&quot;${PROJECT_VERSION_PATCH}&quot;</span>)
</code></pre>
</li>
<li><p>&#x8BBE;&#x7F6E;&#x4E86;&#x5728;&#x5305;&#x88C5;&#x7684;&#x65F6;&#x5019;&#x9700;&#x8981;&#x5FFD;&#x7565;&#x7684;&#x6587;&#x4EF6;&#x5217;&#x8868;&#x548C;&#x76EE;&#x5F55;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">set</span>(CPACK_SOURCE_IGNORE_FILES <span class="hljs-string">&quot;${PROJECT_BINARY_DIR};/.git/;.gitignore&quot;</span>)
</code></pre>
</li>
<li><p>&#x5217;&#x51FA;&#x4E86;&#x6E90;&#x4EE3;&#x7801;&#x5F52;&#x6863;&#x7684;&#x6253;&#x5305;&#x751F;&#x6210;&#x5668;&#x2014;&#x2014;&#x5728;&#x6211;&#x4EEC;&#x7684;&#x4F8B;&#x5B50;&#x4E2D;&#x662F;<code>ZIP</code>&#xFF0C;&#x7528;&#x4E8E;&#x751F;&#x6210;<code>.ZIP</code>&#x5F52;&#x6863;&#xFF0C;<code>TGZ</code>&#x7528;&#x4E8E;<code>.tar.gz</code>&#x5F52;&#x6863;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">set</span>(CPACK_SOURCE_GENERATOR <span class="hljs-string">&quot;ZIP;TGZ&quot;</span>)
</code></pre>
</li>
<li><p>&#x6211;&#x4EEC;&#x8FD8;&#x5217;&#x51FA;&#x4E86;&#x4E8C;&#x8FDB;&#x5236;&#x5B58;&#x6863;&#x751F;&#x6210;&#x5668;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">set</span>(CPACK_GENERATOR <span class="hljs-string">&quot;ZIP;TGZ&quot;</span>)
</code></pre>
</li>
<li><p>&#x73B0;&#x5728;&#x4E5F;&#x53EF;&#x58F0;&#x660E;&#x5E73;&#x53F0;&#x539F;&#x751F;&#x4E8C;&#x8FDB;&#x5236;&#x5B89;&#x88C5;&#x7A0B;&#x5E8F;&#xFF0C;&#x4ECE;DEB&#x548C;RPM&#x5305;&#x751F;&#x6210;&#x5668;&#x5F00;&#x59CB;&#xFF0C;&#x4E0D;&#x8FC7;&#x53EA;&#x9002;&#x7528;&#x4E8E;GNU/Linux:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">if</span>(UNIX)
  <span class="hljs-keyword">if</span>(CMAKE_SYSTEM_NAME <span class="hljs-keyword">MATCHES</span> Linux)
    list(APPEND CPACK_GENERATOR <span class="hljs-string">&quot;DEB&quot;</span>)
    <span class="hljs-keyword">set</span>(CPACK_DEBIAN_PACKAGE_MAINTAINER <span class="hljs-string">&quot;robertodr&quot;</span>)
    <span class="hljs-keyword">set</span>(CPACK_DEBIAN_PACKAGE_SECTION <span class="hljs-string">&quot;devel&quot;</span>)
    <span class="hljs-keyword">set</span>(CPACK_DEBIAN_PACKAGE_DEPENDS <span class="hljs-string">&quot;uuid-dev&quot;</span>)

    list(APPEND CPACK_GENERATOR <span class="hljs-string">&quot;RPM&quot;</span>)
    <span class="hljs-keyword">set</span>(CPACK_RPM_PACKAGE_RELEASE <span class="hljs-string">&quot;1&quot;</span>)
    <span class="hljs-keyword">set</span>(CPACK_RPM_PACKAGE_LICENSE <span class="hljs-string">&quot;MIT&quot;</span>)
    <span class="hljs-keyword">set</span>(CPACK_RPM_PACKAGE_REQUIRES <span class="hljs-string">&quot;uuid-devel&quot;</span>)
  <span class="hljs-keyword">endif</span>()
<span class="hljs-keyword">endif</span>()
</code></pre>
</li>
<li><p>&#x5982;&#x679C;&#x6211;&#x4EEC;&#x5728;Windows&#x4E0A;&#xFF0C;&#x6211;&#x4EEC;&#x4F1A;&#x60F3;&#x8981;&#x751F;&#x6210;&#x4E00;&#x4E2A;NSIS&#x5B89;&#x88C5;&#x7A0B;&#x5E8F;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">if</span>(WIN32 <span class="hljs-keyword">OR</span> MINGW)
  list(APPEND CPACK_GENERATOR <span class="hljs-string">&quot;NSIS&quot;</span>)
  <span class="hljs-keyword">set</span>(CPACK_NSIS_PACKAGE_NAME <span class="hljs-string">&quot;message&quot;</span>)
  <span class="hljs-keyword">set</span>(CPACK_NSIS_CONTACT <span class="hljs-string">&quot;robertdr&quot;</span>)
  <span class="hljs-keyword">set</span>(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL <span class="hljs-keyword">ON</span>)
<span class="hljs-keyword">endif</span>()
</code></pre>
</li>
<li><p>&#x53E6;&#x4E00;&#x65B9;&#x9762;&#xFF0C;&#x5728;macOS&#x4E0A;&#xFF0C;bundle&#x5305;&#x662F;&#x6211;&#x4EEC;&#x7684;&#x5B89;&#x88C5;&#x7A0B;&#x5E8F;&#x7684;&#x9009;&#x62E9;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">if</span>(APPLE)
  list(APPEND CPACK_GENERATOR <span class="hljs-string">&quot;Bundle&quot;</span>)
  <span class="hljs-keyword">set</span>(CPACK_BUNDLE_NAME <span class="hljs-string">&quot;message&quot;</span>)
  <span class="hljs-keyword">configure_file</span>(<span class="hljs-variable">${PROJECT_SOURCE_DIR}</span>/cmake/Info.plist.in Info.plist @ONLY)
  <span class="hljs-keyword">set</span>(CPACK_BUNDLE_PLIST <span class="hljs-variable">${CMAKE_CURRENT_BINARY_DIR}</span>/Info.plist)
  <span class="hljs-keyword">set</span>(CPACK_BUNDLE_ICON <span class="hljs-variable">${PROJECT_SOURCE_DIR}</span>/cmake/coffee.icns)
<span class="hljs-keyword">endif</span>()
</code></pre>
</li>
<li><p>&#x6211;&#x4EEC;&#x5728;&#x73B0;&#x6709;&#x7CFB;&#x7EDF;&#x7684;&#x5305;&#x88C5;&#x751F;&#x6210;&#x5668;&#x4E0A;&#xFF0C;&#x5411;&#x7528;&#x6237;&#x6253;&#x5370;&#x4E00;&#x6761;&#x4FE1;&#x606F;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">message</span>(STATUS <span class="hljs-string">&quot;CPack generators: ${CPACK_GENERATOR}&quot;</span>)
</code></pre>
</li>
<li><p>&#x6700;&#x540E;&#xFF0C;&#x6211;&#x4EEC;&#x5305;&#x62EC;&#x4E86;<code>CPack.cmake</code>&#x6807;&#x51C6;&#x6A21;&#x5757;&#x3002;&#x8FD9;&#x5C06;&#x5411;&#x6784;&#x5EFA;&#x7CFB;&#x7EDF;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x5305;&#x548C;&#x4E00;&#x4E2A;<code>package_source</code>&#x76EE;&#x6807;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">include</span>(CPack)
</code></pre>
</li>
</ol>
<p>&#x73B0;&#x5728;&#x6765;&#x914D;&#x7F6E;&#x8FD9;&#x4E2A;&#x9879;&#x76EE;&#xFF1A;</p>
<pre><code class="lang-shell">$ mkdir -p build
$ cd build
$ cmake ..
</code></pre>
<p>&#x4F7F;&#x7528;&#x4E0B;&#x9762;&#x7684;&#x547D;&#x4EE4;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5217;&#x51FA;&#x53EF;&#x7528;&#x7684;&#x76EE;&#x6807;(&#x793A;&#x4F8B;&#x8F93;&#x51FA;&#x662F;&#x5728;&#x4F7F;&#x7528;Unix Makefile&#x4F5C;&#x4E3A;&#x751F;&#x6210;&#x5668;&#x7684;GNU/Linux&#x7CFB;&#x7EDF;&#x4E0A;&#x83B7;&#x5F97;&#x7684;):</p>
<pre><code class="lang-shell">$ cmake --build . --target help

The following are some of the valid targets for this Makefile:
... all (the default if no target is provided)
... clean
... depend
... install/strip
... install
... package_source
... package
... install/local
... test
... list_install_components
... edit_cache
... rebuild_cache
... hello- world
... message
</code></pre>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x770B;&#x5230;<code>package</code>&#x548C;<code>package_source</code>&#x76EE;&#x6807;&#x662F;&#x53EF;&#x7528;&#x7684;&#x3002;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x4EE5;&#x4E0B;&#x547D;&#x4EE4;&#x751F;&#x6210;&#x6E90;&#x5305;:</p>
<pre><code class="lang-shell">$ cmake --build . --target package_source

Run CPack packaging tool for source...
CPack: Create package using ZIP
CPack: Install projects
CPack: - Install directory: /home/user/cmake-cookbook/chapter-11/recipe-01/cxx-example
CPack: Create package
CPack: - package: /home/user/cmake-cookbook/chapter- 11/recipe-01/cxx-example/build/recipe-01-1.0.0-Source.zip generated.
CPack: Create package using TGZ
CPack: Install projects
CPack: - Install directory: /home/user/cmake-cookbook/chapter- 11/recipe-01/cxx-example
CPack: Create package
CPack: - package: /home/user/cmake-cookbook/chapter-11/recipe-01/cxx-example/build/recipe-01- 1.0.0-Source.tar.gz generated.
</code></pre>
<p>&#x540C;&#x6837;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x6784;&#x5EFA;&#x4E8C;&#x8FDB;&#x5236;&#x5305;:</p>
<pre><code class="lang-shell">$ cmake --build . --target package message-1.0.0-Linux.deb
</code></pre>
<p>&#x4F8B;&#x5B50;&#x4E2D;&#xFF0C;&#x6700;&#x540E;&#x5F97;&#x5230;&#x4E86;&#x4EE5;&#x4E0B;&#x4E8C;&#x8FDB;&#x5236;&#x5305;:</p>
<pre><code class="lang-shell">message-1.0.0-Linux.rpm
message-1.0.0-Linux.tar.gz
message-1.0.0-Linux.zip
</code></pre>
<h2 id="&#x5DE5;&#x4F5C;&#x539F;&#x7406;">&#x5DE5;&#x4F5C;&#x539F;&#x7406;</h2>
<p>CPack&#x53EF;&#x7528;&#x4E8E;&#x751F;&#x6210;&#x7528;&#x4E8E;&#x5206;&#x53D1;&#x7684;&#x5305;&#x3002;&#x751F;&#x6210;&#x6784;&#x5EFA;&#x7CFB;&#x7EDF;&#x65F6;&#xFF0C;&#x6211;&#x4EEC;&#x5728;<code>CMakeCPack.cmake</code>&#x4E2D;&#x5217;&#x51FA;&#x4E86;CPack&#x6307;&#x4EE4;&#xFF0C;&#x7528;&#x4E8E;&#x5728;&#x6784;&#x5EFA;&#x76EE;&#x5F55;&#x4E0B;&#x751F;&#x6210;<code>CPackConfig.cmake</code>&#x3002;&#x5F53;&#x8FD0;&#x884C;&#x4EE5;<code>package</code>&#x6216;<code>package_source</code>&#x76EE;&#x6807;&#x7684;CMake&#x547D;&#x4EE4;&#x65F6;&#xFF0C;CPack&#x4F1A;&#x81EA;&#x52A8;&#x8C03;&#x7528;&#xFF0C;&#x53C2;&#x6570;&#x662F;&#x81EA;&#x52A8;&#x751F;&#x6210;&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x3002;&#x5B9E;&#x9645;&#x4E0A;&#xFF0C;&#x8FD9;&#x4E24;&#x4E2A;&#x65B0;&#x76EE;&#x6807;&#x662F;&#x5BF9;CPack&#x7B80;&#x5355;&#x89C4;&#x5219;&#x7684;&#x4F7F;&#x7528;&#x3002;&#x4E0E;CMake&#x4E00;&#x6837;&#xFF0C;CPack&#x4E5F;&#x6709;&#x751F;&#x6210;&#x5668;&#x7684;&#x6982;&#x5FF5;&#x3002;CMake&#x4E0A;&#x4E0B;&#x6587;&#x4E2D;&#x7684;&#x751F;&#x6210;&#x5668;&#x662F;&#x7528;&#x4E8E;&#x751F;&#x6210;&#x672C;&#x5730;&#x6784;&#x5EFA;&#x811A;&#x672C;&#x7684;&#x5DE5;&#x5177;&#xFF0C;&#x4F8B;&#x5982;Unix Makefile&#x6216;Visual Studio&#x9879;&#x76EE;&#x6587;&#x4EF6;&#xFF0C;&#x800C;CPack&#x4E0A;&#x4E0B;&#x6587;&#x4E2D;&#x7684;&#x751F;&#x6210;&#x5668;&#x662F;&#x7528;&#x4E8E;&#x6253;&#x5305;&#x7684;&#x5DE5;&#x5177;&#x3002;&#x6211;&#x4EEC;&#x5217;&#x51FA;&#x4E86;&#x8FD9;&#x4E9B;&#x53D8;&#x91CF;&#xFF0C;&#x5E76;&#x5BF9;&#x4E0D;&#x540C;&#x7684;&#x5E73;&#x53F0;&#x8FDB;&#x884C;&#x4E86;&#x7279;&#x522B;&#x7684;&#x5173;&#x6CE8;&#xFF0C;&#x4E3A;&#x6E90;&#x5305;&#x548C;&#x4E8C;&#x8FDB;&#x5236;&#x5305;&#x5B9A;&#x4E49;&#x4E86;<code>CPACK_SOURCE_GENERATOR</code>&#x548C;<code>CPACK_GENERATOR</code>&#x53D8;&#x91CF;&#x3002;&#x56E0;&#x6B64;&#xFF0C;<code>DEB</code>&#x5305;&#x751F;&#x6210;&#x5668;&#x5C06;&#x8C03;&#x7528;<code>Debian</code>&#x6253;&#x5305;&#x5B9E;&#x7528;&#x7A0B;&#x5E8F;&#xFF0C;&#x800C;<code>TGZ</code>&#x751F;&#x6210;&#x5668;&#x5C06;&#x8C03;&#x7528;&#x7ED9;&#x5B9A;&#x5E73;&#x53F0;&#x4E0A;&#x7684;&#x5F52;&#x6863;&#x5DE5;&#x5177;&#x3002;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x5728;<code>build</code>&#x76EE;&#x5F55;&#x4E2D;&#x8C03;&#x7528;CPack&#xFF0C;&#x5E76;&#x9009;&#x62E9;&#x8981;&#x4E0E;<code>-G</code>&#x547D;&#x4EE4;&#x884C;&#x9009;&#x9879;&#x4E00;&#x8D77;&#x4F7F;&#x7528;&#x7684;&#x751F;&#x6210;&#x5668;&#x3002;<code>RPM</code>&#x5305;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4EE5;&#x4E0B;&#x6B65;&#x9AA4;&#x751F;&#x6210;:</p>
<pre><code class="lang-shell">$ cd build
$ cpack -G RPM

CPack: Create package using RPM
CPack: Install projects
CPack: - Run preinstall target for: recipe-01
CPack: - Install project: recipe-01
CPack: Create package
CPackRPM: Will use GENERATED spec file: /home/user/cmake-cookbook/chapter-11/recipe-01/cxx-example/build/_CPack_Packages/Linux/RPM/SPECS/recipe-01.spec
CPack: - package: /home/user/cmake-cookbook/chapter-11/recipe-01/cxx-example/build/recipe-01-1.0.0-Linux.rpm generated.
</code></pre>
<p>&#x5BF9;&#x4E8E;&#x4EFB;&#x4F55;&#x53D1;&#x884C;&#x7248;&#xFF0C;&#x65E0;&#x8BBA;&#x662F;&#x6E90;&#x4EE3;&#x7801;&#x8FD8;&#x662F;&#x4E8C;&#x8FDB;&#x5236;&#x6587;&#x4EF6;&#xFF0C;&#x6211;&#x4EEC;&#x53EA;&#x9700;&#x8981;&#x6253;&#x5305;&#x7528;&#x6237;&#x9700;&#x8981;&#x7684;&#x5185;&#x5BB9;&#xFF0C;&#x56E0;&#x6B64;&#x6574;&#x4E2A;&#x6784;&#x5EFA;&#x76EE;&#x5F55;&#x548C;&#x5176;&#x4ED6;&#x4E0E;&#x7248;&#x672C;&#x63A7;&#x5236;&#x76F8;&#x5173;&#x7684;&#x6587;&#x4EF6;&#xFF0C;&#x90FD;&#x5FC5;&#x987B;&#x4ECE;&#x8981;&#x6253;&#x5305;&#x7684;&#x6587;&#x4EF6;&#x5217;&#x8868;&#x4E2D;&#x6392;&#x9664;&#x3002;&#x6211;&#x4EEC;&#x7684;&#x4F8B;&#x5B50;&#x4E2D;&#xFF0C;&#x6392;&#x9664;&#x5217;&#x8868;&#x4F7F;&#x7528;&#x4E0B;&#x9762;&#x7684;&#x547D;&#x4EE4;&#x58F0;&#x660E;&#xFF1A;</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">set</span>(CPACK_SOURCE_IGNORE_FILES <span class="hljs-string">&quot;${PROJECT_BINARY_DIR};/.git/;.gitignore&quot;</span>)
</code></pre>
<p>&#x6211;&#x4EEC;&#x8FD8;&#x9700;&#x8981;&#x6307;&#x5B9A;&#x5305;&#x7684;&#x57FA;&#x672C;&#x4FE1;&#x606F;&#xFF0C;&#x4F8B;&#x5982;&#xFF1A;&#x540D;&#x79F0;&#x3001;&#x7B80;&#x77ED;&#x63CF;&#x8FF0;&#x548C;&#x7248;&#x672C;&#x3002;&#x8FD9;&#x4E2A;&#x4FE1;&#x606F;&#x662F;&#x901A;&#x8FC7;CMake&#x53D8;&#x91CF;&#x8BBE;&#x7F6E;&#x7684;&#xFF0C;&#x5F53;&#x5305;&#x542B;&#x76F8;&#x5E94;&#x7684;&#x6A21;&#x5757;&#x65F6;&#xFF0C;CMake&#x53D8;&#x91CF;&#x88AB;&#x4F20;&#x9012;&#x7ED9;CPack&#x3002;</p>
<p><strong>NOTE</strong>:<em>&#x7531;&#x4E8E;CMake 3.9&#x4E2D;&#x7684;<code>project()</code>&#x547D;&#x4EE4;&#x63A5;&#x53D7;<code>DESCRIPTION</code>&#x5B57;&#x6BB5;&#xFF0C;&#x8BE5;&#x5B57;&#x6BB5;&#x5E26;&#x6709;&#x4E00;&#x4E2A;&#x63CF;&#x8FF0;&#x9879;&#x76EE;&#x7684;&#x77ED;&#x5B57;&#x7B26;&#x4E32;&#x3002;CMake&#x5C06;&#x8BBE;&#x7F6E;&#x4E00;&#x4E2A;<code>PROJECT_DESCRIPTION</code>&#xFF0C;&#x53EF;&#x4EE5;&#x7528;&#x5B83;&#x6765;&#x91CD;&#x7F6E;<code>CPACK_PACKAGE_DESCRIPTION_SUMMARY</code>&#x3002;</em></p>
<p>&#x8BA9;&#x6211;&#x4EEC;&#x8BE6;&#x7EC6;&#x770B;&#x770B;&#xFF0C;&#x53EF;&#x4EE5;&#x4E3A;&#x793A;&#x4F8B;&#x9879;&#x76EE;&#x751F;&#x6210;&#x7684;&#x4E0D;&#x540C;&#x7C7B;&#x578B;&#x5305;&#x7684;&#x8BF4;&#x660E;&#x3002;</p>
<h3 id="&#x6253;&#x5305;&#x6E90;&#x7801;">&#x6253;&#x5305;&#x6E90;&#x7801;</h3>
<p>&#x6211;&#x4EEC;&#x7684;&#x793A;&#x4F8B;&#x4E2D;&#xFF0C;&#x51B3;&#x5B9A;&#x5BF9;&#x6E90;&#x5B58;&#x6863;&#x4F7F;&#x7528;<code>TGZ</code>&#x548C;<code>ZIP</code>&#x751F;&#x6210;&#x5668;&#x3002;&#x8FD9;&#x4E9B;&#x6587;&#x4EF6;&#x5C06;&#x5206;&#x522B;&#x751F;&#x6210;<code>.tar.gz</code>&#x548C;<code>.zip</code>&#x538B;&#x7F29;&#x6587;&#x4EF6;&#x3002;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x68C0;&#x67E5;&#x751F;&#x6210;&#x7684;<code>.tar.gz</code>&#x6587;&#x4EF6;&#x7684;&#x5185;&#x5BB9;:</p>
<pre><code class="lang-shell">$ tar tzf recipe-01-1.0.0-Source.tar.gz

recipe-01-1.0.0-Source/opt/
recipe-01-1.0.0-Source/opt/recipe-01/
recipe-01-1.0.0-Source/opt/recipe-01/cmake/
recipe-01-1.0.0-Source/opt/recipe-01/cmake/coffee.icns
recipe-01-1.0.0-Source/opt/recipe-01/cmake/Info.plist.in
recipe-01-1.0.0-Source/opt/recipe-01/cmake/messageConfig.cmake.in
recipe-01-1.0.0-Source/opt/recipe-01/CMakeLists.txt
recipe-01-1.0.0-Source/opt/recipe-01/src/
recipe-01-1.0.0-Source/opt/recipe-01/src/Message.hpp
recipe-01-1.0.0-Source/opt/recipe-01/src/CMakeLists.txt
recipe-01-1.0.0-Source/opt/recipe-01/src/Message.cpp
recipe-01-1.0.0-Source/opt/recipe-01/src/hello-world.cpp
recipe-01-1.0.0-Source/opt/recipe-01/LICENSE
recipe-01-1.0.0-Source/opt/recipe-01/tests/
recipe-01-1.0.0-Source/opt/recipe-01/tests/CMakeLists.txt
recipe-01-1.0.0-Source/opt/recipe-01/tests/use_target/
recipe-01-1.0.0-Source/opt/recipe-01/tests/use_target/CMakeLists.txt
recipe-01-1.0.0-Source/opt/recipe-01/tests/use_target/use_message.cpp
recipe-01-1.0.0-Source/opt/recipe-01/INSTALL.md
</code></pre>
<p>&#x4E0E;&#x9884;&#x671F;&#x76F8;&#x540C;&#xFF0C;&#x53EA;&#x5305;&#x542B;&#x6E90;&#x7801;&#x6811;&#x7684;&#x5185;&#x5BB9;&#x3002;&#x6CE8;&#x610F;<code>INSTALL.md</code>&#x548C;<code>LICENSE</code>&#x6587;&#x4EF6;&#x4E5F;&#x5305;&#x62EC;&#x5728;&#x5185;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;<code>CPACK_PACKAGE_DESCRIPTION_FILE</code>&#x548C;<code>CPACK_RESOURCE_FILE_LICENSE</code>&#x53D8;&#x91CF;&#x6307;&#x5B9A;&#x3002;</p>
<p><strong>NOTE</strong>:<em>Visual Studio&#x751F;&#x6210;&#x5668;&#x65E0;&#x6CD5;&#x89E3;&#x6790;<code>package_source</code>&#x76EE;&#x6807;:<a href="https://gitlab.kitware.com/cmake/cmake/issues/13058&#x3002;" target="_blank">https://gitlab.kitware.com/cmake/cmake/issues/13058&#x3002;</a></em></p>
<h3 id="&#x4E8C;&#x8FDB;&#x5236;&#x5305;">&#x4E8C;&#x8FDB;&#x5236;&#x5305;</h3>
<p>&#x521B;&#x5EFA;&#x4E8C;&#x8FDB;&#x5236;&#x5B58;&#x6863;&#x65F6;&#xFF0C;CPack&#x5C06;&#x6253;&#x5305;<code>CMakeCPack.cmake</code>&#x4E2D;&#x63CF;&#x8FF0;&#x7684;&#x76EE;&#x6807;&#x7684;&#x5185;&#x5BB9;&#x3002;&#x56E0;&#x6B64;&#xFF0C;&#x5728;&#x6211;&#x4EEC;&#x7684;&#x793A;&#x4F8B;&#x4E2D;&#xFF0C;hello-world&#x53EF;&#x6267;&#x884C;&#x6587;&#x4EF6;&#x3001;&#x6D88;&#x606F;&#x52A8;&#x6001;&#x5E93;&#x4EE5;&#x53CA;&#x76F8;&#x5E94;&#x7684;&#x5934;&#x6587;&#x4EF6;&#x90FD;&#x5C06;&#x4EE5;<code>.tar.gz</code>&#x548C;<code>.zip</code>&#x7684;&#x683C;&#x5F0F;&#x6253;&#x5305;&#x3002;&#x6B64;&#x5916;&#xFF0C;&#x8FD8;&#x5C06;&#x6253;&#x5305;CMake&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x3002;&#x8FD9;&#x5BF9;&#x4E8E;&#x9700;&#x8981;&#x94FE;&#x63A5;&#x5230;&#x6211;&#x4EEC;&#x7684;&#x5E93;&#x7684;&#x5176;&#x4ED6;&#x9879;&#x76EE;&#x975E;&#x5E38;&#x6709;&#x7528;&#x3002;&#x5305;&#x4E2D;&#x4F7F;&#x7528;&#x7684;&#x5B89;&#x88C5;&#x76EE;&#x5F55;&#x53EF;&#x80FD;&#x4E0E;&#x4ECE;&#x6784;&#x5EFA;&#x6811;&#x4E2D;&#x5B89;&#x88C5;&#x9879;&#x76EE;&#x65F6;&#x4F7F;&#x7528;&#x7684;&#x524D;&#x7F00;&#x4E0D;&#x540C;&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;<code>CPACK_PACKAGING_INSTALL_PREFIX</code>&#x53D8;&#x91CF;&#x6765;&#x5B9E;&#x73B0;&#x8FD9;&#x4E00;&#x70B9;&#x3002;&#x6211;&#x4EEC;&#x7684;&#x793A;&#x4F8B;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x5B83;&#x8BBE;&#x7F6E;&#x4E3A;&#x7CFB;&#x7EDF;&#x4E0A;&#x7684;&#x7279;&#x5B9A;&#x4F4D;&#x7F6E;:<code>/opt/recipe-01</code>&#x3002;</p>
<pre><code class="lang-shell">$ tar tzf recipe-01-1.0.0-Linux.tar.gz

recipe-01- 1.0.0-Linux/opt/
recipe-01-1.0.0-Linux/opt/recipe-01/
recipe-01-1.0.0- Linux/opt/recipe-01/bin/
recipe-01-1.0.0-Linux/opt/recipe-01/bin/hello- world
recipe-01-1.0.0-Linux/opt/recipe-01/share/
recipe-01-1.0.0- Linux/opt/recipe-01/share/cmake/
recipe-01-1.0.0-Linux/opt/recipe- 01/share/cmake/recipe-01/
recipe-01-1.0.0-Linux/opt/recipe- 01/share/cmake/recipe-01/messageConfig.cmake
recipe-01-1.0.0- Linux/opt/recipe-01/share/cmake/recipe-01/messageTargets-hello- world.cmake
recipe-01-1.0.0-Linux/opt/recipe-01/share/cmake/recipe- 01/messageConfigVersion.cmake
recipe-01-1.0.0-Linux/opt/recipe- 01/share/cmake/recipe-01/messageTargets-hello-world- release.cmake
recipe-01-1.0.0-Linux/opt/recipe-01/share/cmake/recipe- 01/messageTargets-release.cmake
recipe-01-1.0.0-Linux/opt/recipe- 01/share/cmake/recipe-01/messageTargets.cmake
recipe-01-1.0.0- Linux/opt/recipe-01/include/
recipe-01-1.0.0-Linux/opt/recipe- 01/include/message/
recipe-01-1.0.0-Linux/opt/recipe- 01/include/message/Message.hpp
recipe-01-1.0.0-Linux/opt/recipe- 01/include/message/messageExport.h
recipe-01-1.0.0-Linux/opt/recipe- 01/lib64/
recipe-01-1.0.0-Linux/opt/recipe- 01/lib64/libmessage.so
recipe-01-1.0.0-Linux/opt/recipe- 01/lib64/libmessage.so.1`
</code></pre>
<h3 id="&#x5E73;&#x53F0;&#x539F;&#x751F;&#x7684;&#x4E8C;&#x8FDB;&#x5236;&#x5B89;&#x88C5;">&#x5E73;&#x53F0;&#x539F;&#x751F;&#x7684;&#x4E8C;&#x8FDB;&#x5236;&#x5B89;&#x88C5;</h3>
<p>&#x6211;&#x4EEC;&#x5E0C;&#x671B;&#x6BCF;&#x4E2A;&#x5E73;&#x53F0;&#x539F;&#x751F;&#x4E8C;&#x8FDB;&#x5236;&#x5B89;&#x88C5;&#x7A0B;&#x5E8F;&#x7684;&#x914D;&#x7F6E;&#x7565;&#x6709;&#x4E0D;&#x540C;&#x3002;&#x53EF;&#x4EE5;&#x5728;&#x5355;&#x4E2A;<code>CMakeCPack.cmake</code>&#x4E2D;&#x4F7F;&#x7528;CPack&#x7BA1;&#x7406;&#x8FD9;&#x4E9B;&#x5DEE;&#x5F02;&#xFF0C;&#x5C31;&#x50CF;&#x4F8B;&#x5B50;&#x4E2D;&#x505A;&#x7684;&#x90A3;&#x6837;&#x3002;</p>
<p>&#x5BF9;&#x4E8E;GNU/Linux&#x7CFB;&#x7EDF;&#xFF0C;&#x914D;&#x7F6E;&#x4E86;<code>DEB</code>&#x548C;<code>RPM</code>&#x751F;&#x6210;&#x5668;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">if</span>(UNIX)
  <span class="hljs-keyword">if</span>(CMAKE_SYSTEM_NAME <span class="hljs-keyword">MATCHES</span> Linux)
    list(APPEND CPACK_GENERATOR <span class="hljs-string">&quot;DEB&quot;</span>)
    <span class="hljs-keyword">set</span>(CPACK_DEBIAN_PACKAGE_MAINTAINER <span class="hljs-string">&quot;robertodr&quot;</span>)
    <span class="hljs-keyword">set</span>(CPACK_DEBIAN_PACKAGE_SECTION <span class="hljs-string">&quot;devel&quot;</span>)
    <span class="hljs-keyword">set</span>(CPACK_DEBIAN_PACKAGE_DEPENDS <span class="hljs-string">&quot;uuid-dev&quot;</span>)

    list(APPEND CPACK_GENERATOR <span class="hljs-string">&quot;RPM&quot;</span>)
    <span class="hljs-keyword">set</span>(CPACK_RPM_PACKAGE_RELEASE <span class="hljs-string">&quot;1&quot;</span>)
    <span class="hljs-keyword">set</span>(CPACK_RPM_PACKAGE_LICENSE <span class="hljs-string">&quot;MIT&quot;</span>)
    <span class="hljs-keyword">set</span>(CPACK_RPM_PACKAGE_REQUIRES <span class="hljs-string">&quot;uuid-devel&quot;</span>)
  <span class="hljs-keyword">endif</span>()
<span class="hljs-keyword">endif</span>()
</code></pre>
<p>&#x6211;&#x4EEC;&#x7684;&#x793A;&#x4F8B;&#x4F9D;&#x8D56;&#x4E8E;UUID&#x5E93;&#xFF0C;<code>CPACK_DEBIAN_PACKAGE_DEPENDS</code>&#x548C;<code>cpack_rpm_package_require</code>&#x9009;&#x9879;&#x5141;&#x8BB8;&#x6307;&#x5B9A;&#xFF0C;&#x5305;&#x548C;&#x6570;&#x636E;&#x5E93;&#x4E2D;&#x5BF9;&#x5176;&#x4ED6;&#x5305;&#x7684;&#x4F9D;&#x8D56;&#x5173;&#x7CFB;&#x3002;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;dpkg&#x548C;rpm&#x7A0B;&#x5E8F;&#x5206;&#x522B;&#x5206;&#x6790;&#x751F;&#x6210;&#x7684;<code>.deb</code>&#x548C;<code>.rpm</code>&#x5305;&#x7684;&#x5185;&#x5BB9;&#x3002;</p>
<p>&#x6CE8;&#x610F;&#xFF0C;<code>CPACK_PACKAGING_INSTALL_PREFIX</code>&#x4E5F;&#x4F1A;&#x5F71;&#x54CD;&#x8FD9;&#x4E9B;&#x5305;&#x751F;&#x6210;&#x5668;&#xFF1A;&#x6211;&#x4EEC;&#x7684;&#x5305;&#x5C06;&#x5B89;&#x88C5;&#x5230;<code>/opt/recipe-01</code>&#x3002;</p>
<p>CMake&#x771F;&#x6B63;&#x63D0;&#x4F9B;&#x4E86;&#x8DE8;&#x5E73;&#x53F0;&#x548C;&#x53EF;&#x79FB;&#x690D;&#x6784;&#x5EFA;&#x7CFB;&#x7EDF;&#x7684;&#x652F;&#x6301;&#x3002;&#x4E0B;&#x9762;&#x5C06;&#x4F7F;&#x7528;Nullsoft&#x811A;&#x672C;&#x5B89;&#x88C5;&#x7CFB;&#x7EDF;(NSIS)&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x5B89;&#x88C5;&#x7A0B;&#x5E8F;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">if</span>(WIN32 <span class="hljs-keyword">OR</span> MINGW)
  list(APPEND CPACK_GENERATOR <span class="hljs-string">&quot;NSIS&quot;</span>)
  <span class="hljs-keyword">set</span>(CPACK_NSIS_PACKAGE_NAME <span class="hljs-string">&quot;message&quot;</span>)
  <span class="hljs-keyword">set</span>(CPACK_NSIS_CONTACT <span class="hljs-string">&quot;robertdr&quot;</span>)
  <span class="hljs-keyword">set</span>(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL <span class="hljs-keyword">ON</span>)
<span class="hljs-keyword">endif</span>()
</code></pre>
<p>&#x5982;&#x679C;&#x5728;macOS&#x4E0A;&#x6784;&#x5EFA;&#x9879;&#x76EE;&#xFF0C;&#x5C06;&#x542F;&#x7528;<code>Bundle packager</code>:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">if</span>(APPLE)
  list(APPEND CPACK_GENERATOR <span class="hljs-string">&quot;Bundle&quot;</span>)
  <span class="hljs-keyword">set</span>(CPACK_BUNDLE_NAME <span class="hljs-string">&quot;message&quot;</span>)
  <span class="hljs-keyword">configure_file</span>(<span class="hljs-variable">${PROJECT_SOURCE_DIR}</span>/cmake/Info.plist.in Info.plist @ONLY)
  <span class="hljs-keyword">set</span>(CPACK_BUNDLE_PLIST <span class="hljs-variable">${CMAKE_CURRENT_BINARY_DIR}</span>/Info.plist)
  <span class="hljs-keyword">set</span>(CPACK_BUNDLE_ICON <span class="hljs-variable">${PROJECT_SOURCE_DIR}</span>/cmake/coffee.icns)
<span class="hljs-keyword">endif</span>()
</code></pre>
<p>macOS&#x7684;&#x793A;&#x4F8B;&#x4E2D;&#xFF0C;&#x9700;&#x8981;&#x4E3A;&#x5305;&#x914D;&#x7F6E;&#x5C5E;&#x6027;&#x5217;&#x8868;&#x6587;&#x4EF6;&#xFF0C;&#x8FD9;&#x662F;&#x901A;&#x8FC7;<code>configure_file</code>&#x5B9E;&#x73B0;&#x7684;&#x3002;<code>Info.plist</code>&#x7684;&#x4F4D;&#x7F6E;&#x548C;&#x5305;&#x7684;&#x56FE;&#x6807;&#xFF0C;&#x8FD9;&#x4E9B;&#x90FD;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;CPack&#x7684;&#x53D8;&#x91CF;&#x8FDB;&#x884C;&#x8BBE;&#x7F6E;&#x3002;</p>
<p><strong>NOTE</strong>:<em>&#x53EF;&#x4EE5;&#x5728;&#x8FD9;&#x91CC;&#x9605;&#x8BFB;&#xFF0C;&#x5173;&#x4E8E;&#x5C5E;&#x6027;&#x5217;&#x8868;&#x683C;&#x5F0F;&#x7684;&#x66F4;&#x591A;&#x4FE1;&#x606F;:<a href="https://en.wikipedia.org/wiki/Property_list" target="_blank">https://en.wikipedia.org/wiki/Property_list</a></em></p>
<h2 id="&#x66F4;&#x591A;&#x4FE1;&#x606F;">&#x66F4;&#x591A;&#x4FE1;&#x606F;</h2>
<p>&#x5BF9;<code>CMakeCPack.cmake</code>&#x8FDB;&#x884C;&#x8BBE;&#x7F6E;&#xFF0C;&#x8981;&#x6BD4;&#x5217;&#x51FA;CPack&#x7684;&#x914D;&#x7F6E;&#x9009;&#x9879;&#x7B80;&#x5355;&#x7684;&#x591A;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5C06;<code>CPACK_*</code>&#x53D8;&#x91CF;&#x7684;&#x6BCF;&#x4E2A;&#x751F;&#x6210;&#x5668;&#x8BBE;&#x7F6E;&#x653E;&#x5728;&#x5355;&#x72EC;&#x7684;&#x6587;&#x4EF6;&#x4E2D;&#xFF0C;&#x6BD4;&#x5982;<code>CMakeCPackOptions.cmake</code>&#xFF0C;&#x5E76;&#x5C06;&#x8FD9;&#x4E9B;&#x8BBE;&#x7F6E;&#x5305;&#x542B;&#x5230;<code>CMakeCPack.cmake</code>&#x4F7F;&#x7528;<code>set(CPACK_PROJECT_CONFIG_FILE &quot;${PROJECT_SOUsRCE_DIR}/CMakeCPackOptions.cmake&quot;)</code>&#x5C06;&#x8BBE;&#x7F6E;&#x5305;&#x542B;&#x5165;<code>CMakeCPack.cmake</code>&#x4E2D;&#x3002;&#x8FD8;&#x53EF;&#x4EE5;&#x5728;CMake&#x65F6;&#x914D;&#x7F6E;&#x8BE5;&#x6587;&#x4EF6;&#xFF0C;&#x7136;&#x540E;&#x5728;CPack&#x65F6;&#x5305;&#x542B;&#x8BE5;&#x6587;&#x4EF6;&#xFF0C;&#x8FD9;&#x4E3A;&#x914D;&#x7F6E;&#x591A;&#x683C;&#x5F0F;&#x5305;&#x751F;&#x6210;&#x5668;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x79CD;&#x7B80;&#x6D01;&#x7684;&#x65B9;&#x6CD5;(&#x53C2;&#x89C1;<a href="https://cmake.org/cmake/help/v3.6/module/CPack.html" target="_blank">https://cmake.org/cmake/help/v3.6/module/CPack.html</a> )&#x3002;</p>
<p>&#x4E0E;CMake&#x4E2D;&#x7684;&#x6240;&#x6709;&#x5DE5;&#x5177;&#x4E00;&#x6837;&#xFF0C;CPack&#x529F;&#x80FD;&#x5F3A;&#x5927;&#x3001;&#x529F;&#x80FD;&#x591A;&#x6837;&#xFF0C;&#x5E76;&#x4E14;&#x63D0;&#x4F9B;&#x4E86;&#x66F4;&#x591A;&#x7684;&#x7075;&#x6D3B;&#x6027;&#x548C;&#x9009;&#x9879;&#x3002;&#x611F;&#x5174;&#x8DA3;&#x7684;&#x8BFB;&#x8005;&#x5E94;&#x8BE5;&#x770B;&#x5B98;&#x65B9;&#x6587;&#x6863;&#x7684;&#x547D;&#x4EE4;&#x884C;&#x754C;&#x9762;CPack (<a href="https://cmake.org/cmake/help/v3.6/manual/cpack.1.html" target="_blank">https://cmake.org/cmake/help/v3.6/manual/cpack.1.html</a> )&#x624B;&#x518C;&#x9875;&#xFF0C;&#x5982;&#x4F55;&#x4F7F;&#x7528;CPack&#x751F;&#x6210;&#x5668;&#x6253;&#x5305;&#x76F8;&#x5173;&#x9879;&#x76EE;&#x7684;&#x66F4;&#x591A;&#x7EC6;&#x8282;(<a href="https://cmake.org/cmake/help/v3.6/module/CPack.html" target="_blank">https://cmake.org/cmake/help/v3.6/module/CPack.html</a> )&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="11.0-chinese.html" class="navigation navigation-prev " aria-label="Previous page: 第11章 打包项目">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="11.2-chinese.html" class="navigation navigation-next " aria-label="Next page: 11.2 通过PyPI发布使用CMake/pybind11构建的C++/Python项目">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"11.1 生成源代码和二进制包","level":"1.14.1","depth":2,"next":{"title":"11.2 通过PyPI发布使用CMake/pybind11构建的C++/Python项目","level":"1.14.2","depth":2,"path":"content/chapter11/11.2-chinese.md","ref":"content/chapter11/11.2-chinese.md","articles":[]},"previous":{"title":"第11章 打包项目","level":"1.14","depth":1,"path":"content/chapter11/11.0-chinese.md","ref":"content/chapter11/11.0-chinese.md","articles":[{"title":"11.1 生成源代码和二进制包","level":"1.14.1","depth":2,"path":"content/chapter11/11.1-chinese.md","ref":"content/chapter11/11.1-chinese.md","articles":[]},{"title":"11.2 通过PyPI发布使用CMake/pybind11构建的C++/Python项目","level":"1.14.2","depth":2,"path":"content/chapter11/11.2-chinese.md","ref":"content/chapter11/11.2-chinese.md","articles":[]},{"title":"11.3 通过PyPI发布使用CMake/CFFI构建C/Fortran/Python项目","level":"1.14.3","depth":2,"path":"content/chapter11/11.3-chinese.md","ref":"content/chapter11/11.3-chinese.md","articles":[]},{"title":"11.4 以Conda包的形式发布一个简单的项目","level":"1.14.4","depth":2,"path":"content/chapter11/11.4-chinese.md","ref":"content/chapter11/11.4-chinese.md","articles":[]},{"title":"11.5 将Conda包作为依赖项发布给项目","level":"1.14.5","depth":2,"path":"content/chapter11/11.5-chinese.md","ref":"content/chapter11/11.5-chinese.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["-lunr","-search","search-pro","-sharing","github","pageview-count"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"github":{"url":"https://github.com/arcticfox1919"},"search-pro":{},"pageview-count":{},"highlight":{},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"陈晓伟 chenxiaowei","pdf":{"pageNumbers":false,"fontSize":30,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":30,"left":30,"top":30,"bottom":50}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"《CMake Cookbook》中文版","language":"zh-hans","gitbook":"*","description":"作为对《CMake Cookbook》英文版的中文翻译。","direction":"ltr"},"file":{"path":"content/chapter11/11.1-chinese.md","mtime":"2020-09-22T10:39:01.897Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-09-22T11:21:21.825Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-pageview-count/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

